/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.05.00
 *Time:00:00
 */
   public class Main{

    public static void main4(String[] args) {

        //拼接的使用
        StringBuffer stringBuffer = new StringBuffer();
        long start1 = System.currentTimeMillis();//记录当前时间
        for (int i = 0; i < 1000; i++) {
            stringBuffer.append(i);//
        }
        long end1 = System.currentTimeMillis();//记录拼接完成时间
        System.out.println("time1 :" + (end1 - start1));


        StringBuilder stringBuilder = new StringBuilder();
        long start2 = System.currentTimeMillis();//记录开始拼接的起始时间
        for (int i = 0; i < 1000; i++) {
            stringBuilder.append(i);
        }
        long end2 = System.currentTimeMillis();//记录拼接完成后的时间
        System.out.println("time2 :" + (end2 - start2));

        //String类型的+拼接
        String s = "";
        long start3  = System.currentTimeMillis();//记录当前时间
        for (int i = 0; i < 1000; i++) {
            s = s + i;
        }
        long end3 = System.currentTimeMillis();//拼接完成后的时间
        System.out.println("time3 :" + (end3 - start3));
    }
    public static void main(String[] args) {
//        //拼接的使用
//        StringBuffer stringBuffer = new StringBuffer();
//        for (int i = 0; i < 10; i++) {
//            stringBuffer.append(i);//
//        }
//        System.out.println(stringBuffer);
//
//        StringBuilder stringBuilder = new StringBuilder();
//        for (int i = 0; i < 10; i++) {
//            stringBuilder.append(i);
//        }
//        System.out.println(stringBuilder);
//    }

//    public static void main3(String[] args) {
//
//        String s = "119.75.217.109";
//        String[] strings = s.split("\\.");//按照'.'分割
//
//        System.out.print("IP: ");
//        for (int i = 0; i < strings.length; i++) {
//                System.out.print(strings[i]);
//            if(!(i == strings.length - 1))
//                System.out.print(".");
//        }

        String s = "I am a humorous person.";
        String[] strings = s.split(" ");//按照空格分割

        //for-each循环遍历数组
        for(String tem : strings){
            System.out.print(tem + " ");
        }

//        String s = "abccba";
//        String s1 = s.replace('a','A');
//        String s2 = s.replace("abc","cba");
//        String s3 = s.replaceAll("abc","ABC");
//        System.out.println("s1 = " + s1);
//        System.out.println("s2 = " + s2);
//        System.out.println("s3 = " + s3);

//        String str1 = "1234";
//        String str2 = "3.14";
//        //转换
//        int data1 = Integer.parseInt(str1);//"1234" - > 1234
//        double data2 = Double.parseDouble(str2);//"3.14" -> 3.14
//        //输出
//        System.out.println("data1 = " + data1);
//        System.out.println("data2 = " + data2);

//
//        int data1 = 1234;
//        double data2 = 3.14;
//
//        //转换
//        String s1 = String.valueOf(data1);//"1234"
//        String s2 = String.valueOf(data2);//"3.14"
//
//        //输出
//        System.out.println("s1 = " + s1);
//        System.out.println("s2 = " + s2);
//
//        String s1 = "abcdefg";
//        String s2 = "ABCDEFG";
//        //转换后输出
//        System.out.println("s1 = " + s1.toUpperCase());//"ABCDEF"
//        System.out.println("s2 = " + s2.toLowerCase());//"abcdef"

//        String s = "See you again!";
//        //截取
//        //指定位置开始截取
//        String s1 = s.substring(8);//again!
//        //指定区间截取
//        String s2 = s.substring(0,3);//左闭右开【0，2）:See
//        //输出
//        System.out.println("s1 = " + s1);
//        System.out.println("s2 = " + s2);

//        String s = new String("abcd");
//        //使用intern方法
//        String s1 = s.intern();//在字符串常量池中存储s引用
//        //此时“abcd"是字符串常量
//        String s2 = "abcd";
//
//        System.out.println(s2 == s1);//true
  }

    public static void main3(String[] args) {
        String s = "abcdefg";
//        //charAt()找到当前下标的元素，与数组通过下标访问元素类似
//        System.out.println(s.charAt(0));//找到0下标的字符，返回类型是char
        //找到字符‘a’；找到引用指向对象第一次出现字符‘a'的下标：0
        System.out.println(s.lastIndexOf('a'));//找到了：0
        System.out.println(s.lastIndexOf('A'));//找不到：-1

        System.out.println(s.lastIndexOf('c',2));//返回2
        System.out.println(s.lastIndexOf("abc"));//查找”abc"字符串，默认末尾下标查找，返回0
        System.out.println(s.lastIndexOf("fg",3));//查找“fg"，从3下标查找，返回-1
    }

    public static void main2(String[] args) {

        String s1 = "abc";
        String s2 = new String("abc");
        System.out.println(s1 == s2);

    }
    public static void main1(String[] args) {
        //1.直接复制字符串常量
        String string = "abcdef";
        //2.通过String()方法新创建一个字符串对象后赋值
        String s = new String("abc");
        //3.创建数组，将数组通过String()方法转换为字符串
        char[] chars = new char[]{'a','b','c','d'};
        String s1 =  new String(chars);

        //输出
        System.out.println("string = " + string);
        System.out.println("s = " + s);
        System.out.println("s1 = " + s1);
    }
}